/**
 * plant导航页面相关
 */
import { reactive, ref, computed } from "vue";
import type { IPlantItem } from "@/simba/types";

import sheep from '@/sheep';
const user = computed(() => sheep.$store('user').userInfo);
//植物（plan.vue）页面中 顶部的 位置、品种的选择


// function toLocBreedEdit(type: String, locBreed?:ILocationBreed){
	
// }

const defaultPlant = ref([
	{
		id: 1,
		name: '月季1',
		url: 'https://uview-plus.jiangruyi.com/album/1.jpg',
		temprature: 21,
		humidity: 51,
		checked: true
	},
	{
		id:2,
		name: '月季2',
		url: 'https://uview-plus.jiangruyi.com/album/2.jpg',
		temprature: 22,
		humidity: 52,
		checked: true
	},
	{
		id: 3,
		name: '月季3',
		url: 'https://uview-plus.jiangruyi.com/album/3.jpg',
		temprature: 23,
		humidity: 53,
		checked: true
	},
	{
		id:4,
		name: '月季4',
		url: 'https://uview-plus.jiangruyi.com/album/4.jpg',
		temprature: 23,
		humidity: 54,
		checked: true
	},
	{
		id:5,
		name: '月季5',
		url: 'https://uview-plus.jiangruyi.com/album/4.jpg',
		temprature: 23,
		humidity: 54,
		checked: true
	},
	{
		id: 6,
		name: '月季6',
		url: 'https://uview-plus.jiangruyi.com/album/4.jpg',
		temprature: 23,
		humidity: 54,
		checked: true
	},
	{
		id:7,
		name: '月季7',
		url: 'https://uview-plus.jiangruyi.com/album/4.jpg',
		temprature: 23,
		humidity: 54,
		checked: true
	}
])

export const usePlantListWater=()=>{
	let listPlantWater = reactive<IPlantItem[]>([])
	
	function onGetPlantListWater(){
		defaultPlant.value.map((item, index) => {
			listPlantWater.push(item)
		})
	}
	function onBatchWaterHandler(){
		uni.showToast({
			icon:'none',
			title:'onBatchWaterHandler'
		})
	}
	function onWaterTodayHandler( obj: IPlantItem){
		console.log(obj)
		uni.showToast({
			icon:'none',
			title:'onWaterTodayHandler' + obj.name
		})
	}
	// const itemName = ref('')
	function onWaterTomorrowHandler(obj:IPlantItem){		
		const {name, url} = obj
		console.log(name)
		uni.showToast({
			icon:'none',
			title:'onWaterTodayHandler' + url
		})
	}
	return {
		listPlantWater, onGetPlantListWater, 
		onBatchWaterHandler, onWaterTodayHandler, onWaterTomorrowHandler
	}
}

export const usePlantListFertilize=()=>{
	let listPlantFertilize = reactive<IPlantItem[]>([])
	
	function onGetPlantListFertilize() {
		defaultPlant.value.forEach((item, index) => {
			listPlantFertilize.push(item)
		})
	}
	
	function onBatchFertilizeHandler(){
		uni.showToast({
			icon:'none',
			title:'onBatchFertilizeHandler'
		})
	}
	function onFertilizeTodayHandler( obj: IPlantItem){
		console.log(obj)
		uni.showToast({
			icon:'none',
			title:'onFertilizeTodayHandler' + obj.name
		})
	}
	// const itemName = ref('')
	function onFertilizeTomorrowHandler(obj:IPlantItem){		
		const {name, url} = obj
		console.log(name)
		uni.showToast({
			icon:'none',
			title:'onFertilizeTomorrowHandler' + url
		})
	}
	return {
		listPlantFertilize, onGetPlantListFertilize,
		onBatchFertilizeHandler, onFertilizeTodayHandler, onFertilizeTomorrowHandler
	}
}

export const usePlantListLocation = () => {
	let listPlantLocation = reactive<IPlantItem[]>([])
	
	function onGetPlantListLocation() {
		Object.assign(listPlantLocation, defaultPlant.value)
		// listPlantLocation.push(defaultPlant.value)
	}
	/**
	 * 养护
	 * @return 
	 */ 
	function onConserveLocationHandler(obj: IPlantItem) {
		// console.log(obj.id, obj.name)
		// uni.showToast({
		// 	icon: 'none',
		// 	title: 'onConservLocationHandler' + obj.name
		// })
		uni.navigateTo({
			url:'/pages/plant/conserve/conserve?pId=' + obj.id
		});
	}
	/**
	 * 状态
	 * @param {IPlantItem} obj 
	 * @return 
	 */ 
	function onStatusLocationHandler(obj: IPlantItem) {
		console.log(obj)
		uni.showToast({
			icon: 'none',
			title: 'onStatusLocationHandler' + obj.name
		})
	}
	/**
	 * 生长记录
	 * @param {IPlantItem} obj 
	 * @return 
	 */
	function onGrowRecordLocationHandler(obj: IPlantItem) {
		const { name, url } = obj
		// console.log(name)
		// uni.showToast({
		// 	icon: 'none',
		// 	title: 'onGrowRecordLocationHandler' + url
		// })
		uni.navigateTo({
			url:"/pages/plant/growRecord/growRecord?pId=" + obj.id
		});
	}
	return {
		listPlantLocation, onGetPlantListLocation,
		onConserveLocationHandler, onStatusLocationHandler, onGrowRecordLocationHandler
	}
}

/**
 * 按品种获取植物列表
 */
export const usePlantListBreed = () => {
	let listPlantBreed = reactive<IPlantItem[]>([])
	
	function onGetPlantListBreed() {
		defaultPlant.value.map((item, index) => {
			listPlantBreed.push(item)
		})
	}
	/**
	 * 养护
	 * @return 
	 */ 
	function onConserveBreedHandler(obj: IPlantItem) {
		uni.showToast({
			icon: 'none',
			title: 'onBatchBreedHandler'
		})
	}
	/**
	 * 状态
	 * @param {IPlantItem} obj 
	 * @return 
	 */ 
	function onStatusBreedHandler(obj: IPlantItem) {
		console.log(obj)
		uni.showToast({
			icon: 'none',
			title: 'onBreedTodayHandler' + obj.name
		})
	}
	/**
	 * 生长记录
	 * @param {IPlantItem} obj 
	 * @return 
	 */
	function onGrowRecordBreedHandler(obj: IPlantItem) {
		const { name, url } = obj
		// console.log(name)
		// uni.showToast({
		// 	icon: 'none',
		// 	title: 'onBreedrTodayHandler' + url
		// })
		uni.navigateTo({
			url:"/pages/plant/growRecord/growRecord"
		});
	}
	return {
		listPlantBreed, onGetPlantListBreed,
		onConserveBreedHandler, onStatusBreedHandler, onGrowRecordBreedHandler
	}
}